<?php

class PointSaleController extends WebController{
    
    public function processRequest($action_type,  HttpRequest $request,HttpResponse $response) {
        switch ($action_type){
            case "deletePointSale":
                $this->deletePointSale($request,$response);
                break;
        }
    }

    protected function display(HttpRequest $request,HttpResponse $response) {
       $point_sale = new PointSaleRM();
       $this->orm_builder->buildPointSale($point_sale);
       $point_sale->findAllValidPointSale();
       $request->setAttribute("point_sale", $point_sale); 
       $this->forward("point_sale.html",$request);
    }
    
    protected function deletePointSale(HttpRequest $request,HttpResponse $response){
        if($request->get("id") == null){
            $this->sendRedirect("/point-sale", $response);
        }
        
        //Load point sale information
        $point_sale = new PointSaleRM();
        $point_sale->ID = $request->get("id");
        $point_sale->map();
        //Check required information is not valid
        if($point_sale->SUPPLIER_ID != $this->_USER_ID){
            $this->sendRedirect("/point-sale", $response);
        }
        PointSaleRM::delete($point_sale);
        $this->sendRedirect("/point-sale", $response);
    }

}

